﻿
Imports std

Public Class node
    Private Class properties
        Inherits map(Of String, iproperty)

        Public ReadOnly pl As property_list = Nothing
        Private ReadOnly id As Int64 = 0
        Private initialized As Boolean = False

        Public Sub New(ByVal id As Int64)
            Me.id = id

            pl = New property_list(id)
            data(constants.properties.property_list_name) = pl
            start()
        End Sub

        Public Function waitfor_initialized() As Boolean
            Return waitfor(Function() initialized)
        End Function

        Private Sub start()
            Dim ps As pointer(Of [set](Of String)) = Nothing
            Dim ec As eventComb = Nothing
            assert_begin(New eventComb(Function() As Boolean
                                           ps = New pointer(Of [set](Of String))()
                                           ec = pl.get_data(ps)
                                           Return waitfor(ec) AndAlso
                                                  goto_next()
                                       End Function,
                                       Function() As Boolean
                                           If ec.end_result() Then
                                               assert(Not +ps Is Nothing)
                                               Dim it As [set](Of String).iterator = Nothing
                                               it = (+ps).begin()
                                               While it <> (+ps).end()
                                                   Dim p As iproperty = Nothing
                                                   Dim n As String = Nothing
                                                   p = [property].create((+it), n)
                                                   If p Is Nothing Then
                                                       raiseError(errorHandle.errorType.warning,
                                                                  "failed to create property for node ", id,
                                                                  ", property type ", (+it))
                                                   Else
                                                       Me(n) = p
                                                   End If

                                                   it += 1
                                               End While
                                           End If
                                           initialized = True
                                           Return goto_end()
                                       End Function))
        End Sub
    End Class
End Class
